package com.hnxxxy.sysmgr.controller;

import com.github.pagehelper.PageHelper;
import com.hnxxxy.common.AjaxRtnEntity.AjaxRtnEntity;
import com.hnxxxy.common.annotation.LogAnno;
import com.hnxxxy.common.tools.Help;
import com.hnxxxy.common.tools.TableObj;
import com.hnxxxy.sysmgr.pojo.Log;
import com.hnxxxy.sysmgr.service.SysLogSercice;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/sys")
@RestController
@Slf4j
public class SysLogController {

    @Autowired
    SysLogSercice sysLogSercice;

    @RequestMapping("/f/sysLog")
    @LogAnno(description = "查询系统日志")
    public TableObj findAlSysLog(TableObj tableObj, Log log){
        if (log.getDescribe() == ""){
            log.setDescribe(null);
        }
        if (log.getStartTime() == ""){
            log.setStartTime(null);
        }
        if (log.getEndTime() == ""){
            log.setEndTime(null);
        }
        PageHelper.startPage(tableObj.getCurr(), tableObj.getNums());
        List<Log> list = sysLogSercice.findAlSysLog(log);
        return Help.getPageTableRtn(tableObj,list);
    }

    @RequestMapping("/d/sysLog")
    @LogAnno(description = "系统日志删除",descriptiontype = "deleteSysLog")
    public AjaxRtnEntity deleteSysLog(@RequestParam("ids[]") Integer[] ids){
        AjaxRtnEntity ajaxRtnEntity=new AjaxRtnEntity(sysLogSercice.deleteSysLog(ids),"删除成功",null);
        return ajaxRtnEntity;
    }

}
